package link;

/**
 * 节点
 * Created by zhaoxin on 2018/7/25.
 */
public class LinkedNode {

    public int data;
    public LinkedNode next;

    public LinkedNode(int data){
        this.data = data;
    }


    /**
     * 构造函数创建链表
     * @param arr
     */
    public LinkedNode(int [] arr){
        if (arr == null || arr.length == 0)
            throw new IllegalArgumentException("参数异常！");
        this.data = arr[0];
        LinkedNode cur = this;

        for (int i = 1; i < arr.length; i++) {
            cur.next = new LinkedNode(arr[i]);
            cur = cur.next;
        }
    }


    @Override
    public String toString() {
        return "LinkedNode{" +
                "data=" + data +
                ", next=" + next +
                '}';
    }


    public static void main(String[] args) {
        int [] arr = {1,2,3,4,5,6};
        LinkedNode head = new LinkedNode(arr);

        System.out.println(head);

    }
}
